<?php
class Application_Model_Group implements Zend_Acl_Role_Interface {
	private $_id;
	private $_name;

	public function getId() {
		return $this->_id;
	}

	public function getName() {
		return $this->_name;
	}

	public function setId($id) {
		$this->_id = $id;
	}

	public function setName($name) {
		$this->_name = $name;
	}

	public static function findByName($name) {
		$db = Zend_Db::factory ( 'Pdo_Mysql', array (
		'host' => 'localhost', 
		'username' => 'root', 
		'password' => '', 
		'dbname' => 'test' )
		 );

		$sql = 'SELECT id, name
                        FROM groups
                        WHERE name = ?';

		$row = $db->fetchRow($sql, array($name), Zend_Db::FETCH_ASSOC);
		$group = new Application_Model_Group();

		$group->setId($row['id']);
		$group->setName($row['name']);
		return $group;
	}

	public static function findById($id) {
		$db = Zend_Db::factory ( 'Pdo_Mysql', array (
		'host' => 'localhost', 
		'username' => 'root', 
		'password' => '', 
		'dbname' => 'test' )
		 );

		$sql = 'SELECT id, name
                        FROM groups
                        WHERE id = ?';

		$row = $db->fetchRow($sql, array($id), Zend_Db::FETCH_ASSOC);
		$group = new Application_Model_Group();

		$group->setId($row['id']);
		$group->setName($row['name']);
		return $group;
	}

	public function getRoleId() {
		return 'group-' . $this->_id;
	}
}